package kr.ac.kookmin.cs.md5match;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Match {

	/**
	 * @param args
	 * @throws NoSuchAlgorithmException 
	 */
	public static void main(String[] args) throws NoSuchAlgorithmException {
		
		System.out.println("start..");
		
		for(long i = 0L ; i < Long.MAX_VALUE ; i++){
			
			if(MD5.getMD5(Long.toString(i)).contains("1234567")){
				System.out.println("catch!! : " + i);
				System.out.println(MD5.getMD5(Long.toString(i)));
				
			}
			
			
		}
		
		System.out.println("end..");
		
	}

}

class MD5 {
    public static String getMD5(String input) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] messageDigest = md.digest(input.getBytes());
            BigInteger number = new BigInteger(1, messageDigest);
            String hashtext = number.toString(16);
            // Now we need to zero pad it if you actually want the full 32 chars.
            while (hashtext.length() < 32) {
                hashtext = "0" + hashtext;
            }
            return hashtext;
        }
        catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
    }

}
